package com.lagou.controller;

import com.lagou.service.CodeService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author czq
 * @date 2020/9/15 16:58
 */
@RestController
@RequestMapping("/api/code")
public class CodeController {

    @Reference
    private CodeService codeService;

    /**
     * ⽣成验证码并发送到对应邮箱，成功true，失败false
     */
    @GetMapping("/create/{email}")
    public boolean create(@PathVariable("email") String email) {
        return codeService.create(email);
    }

    /**
     * 校验验证码是否正确，0正确1错误2超时
     */
    @GetMapping("/validate/{email}/{code}")
    public int validate(@PathVariable("email") String email, @PathVariable("code") String code) {
        return codeService.validate(email, code);
    }
}
